package com.zengzhi.mydesignmode.observermode.javaobservermode;

import java.util.Observable;

/**
 * @author xiejiawei
 * @Date 2021-08-16
 * @Time 21:40
 * 一些注册移除观察者的东西都让父类去做
 */
public class WeatherData extends Observable {

    /**
     * 温度
     */
    private float temperature;

    /**
     * 湿度
     */
    private float humidity;

    /**
     * 压力
     */
    private float pressure;

    WeatherData() {
    }

    /**
     * 当数据更新时，执行通知所有观察者
     */
    public void measurementsChanged() {
        setChanged();
        notifyObservers();
    }

    void setMeasurements(float temperature, float humidity, float pressure) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        measurementsChanged();
    }

    public float getTemperature() {
        return temperature;
    }

    public float getHumidity() {
        return humidity;
    }

    public float getPressure() {
        return pressure;
    }


}
